package com.wzd.imservice.controller;

import com.wzd.commonutils.R;
import com.wzd.imservice.entity.Message;
import com.wzd.imservice.entity.query.HistoryMessageQuery;
import com.wzd.imservice.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ProjectName: e_learning
 * @Package: com.wzd.imservice.controller
 * @ClassName: MessageController
 * @Author: lofxve
 * @Description:
 * @Date: 2021/4/20 10:30
 * @Version: 1.0
 */
@RestController
@Api(tags = "消息管理")
@RequestMapping("/eduim/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @ApiOperation("新增消息")
    @PostMapping("saveMessage")
    public R saveMessage(@RequestBody Message message) {
        boolean flag = messageService.save(message);
        if (flag) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @ApiOperation("获取历史记录")
    @PostMapping("getHistoryMessage")
    public R getHistoryMessage(@RequestBody HistoryMessageQuery historyMessageQuery) {
        List<Message> messages = messageService.getHistoryMessage(historyMessageQuery);
        return R.ok().data("messages", messages);
    }
}
